package 力扣.数组.二维数组;

public class 托普利茨矩阵766 {
    public static void main(String[] args) {
        int[][] ints = {{1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}};
//        int[][] ints = {{1, 2}, {2, 1}};
//        int[][] ints = {{11, 74,0,93}, {40,11,74,7}};
//        int[][] ints = {{1, 2}};
        boolean toeplitzMatrix = isToeplitzMatrix(ints);
        System.out.println(toeplitzMatrix);
    }
    public static boolean isToeplitzMatrix(int[][] matrix) {
        int r = matrix.length;//横坐标
        int c = matrix[0].length;//纵坐标
        //第一列倒数第二个往上一直加直到左上角元素
        for (int i = r-1; i >= 0; i--) {
            int r_1 = i+1;
            int c_1 = 0+1;
            //判断当前元素所在的对角元素
            while ( (r_1 < r) && (c_1 < c) ){
                if (matrix[r_1][c_1] != matrix[r_1 - 1][c_1 - 1]){
                    return false;
                }
                r_1++;
                c_1++;
            }
        }
        //第一行第二个元素一直加到右上角元素
        for (int i = 1; i < c; i++) {
            int r_1 = 0+1;
            int c_1 = i+1;
            //判断当前元素对应的对角元素
            while ( (r_1 < r) && (c_1 < c) ){
                if (matrix[r_1][c_1] != matrix[r_1 - 1][c_1 - 1]){
                    return false;
                }
                r_1++;
                c_1++;
            }
        }
        return true;

    }
}
